<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>设备借还申请</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=201908121454" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=201907231346" type="text/javascript" charset="utf-8"></script>
    <style>
        .mbox {
            padding: 8px;
        }
        .layui-btn {
            margin-left: 10px;
        }
        .layui-btn .layui-icon {
            margin-right: 0px;
        }
        .layui-form-label {
            padding: 8px 15px;
        }
        .layui-card-body {
            display: flex;
            padding: 0px;
        }
        .layui-rt {
            width: 100%;
        }
        .layui-form-select .layui-input{
            height: 32px;
        }
        .layui-tab-title{
            height: 32px;
        }

        .layui-tab-title li{
            height: 33px;
            line-height: 33px;
        }
        .layui-tab layui-tab-card{
            margin-top: -4px;
        }
        .layui-tab-card>.layui-tab-title .layui-this:after {
            border-width: 0px;
        }
        .layui-table{
            margin-top: -2px !important;
        }
        .layui-table-view .layui-table td, .layui-table-view .layui-table th{
            padding: 2px 0;
        }
        #infoId td{
            padding: 5px 2px;
        }
        .tablecolor{
            background-color:#f2f2f2;
        }
        .layui-table{
            width:100%!important;
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-rt">
                <div class="layui-tab layui-tab-card" lay-filter="tabtoggle">
                    <ul class="layui-tab-title">
                        <li class="layui-this">借还申请</li>
                        <li>待批申请</li>
                        <li>已准申请</li>
                        <li>未准申请</li>
                        <li>设备归还</li>
                    </ul>
                    <%--很多选项--%>
                    <div class="layui-tab-content" style="height:100%;padding: 0 10px 10px 10px">
                        <div class="layui-tab-item layui-show">
                            <table class="layui-table" lay-skin="line" id="Settlement" lay-size="sm" lay-filter="SettlementFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">借还设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="deviceDetail" lay-filter="deviceFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="accurateTable" lay-size="sm" lay-filter="accurateTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">借还设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="accurateDetail" lay-filter="accurateFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="approvalTable" lay-size="sm" lay-filter="approvalTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">借还设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="approvalDetail" lay-filter="approvalFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="notexactlyTable" lay-size="sm" lay-filter="notexactlyTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">借还设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="notexactlyDetail" lay-filter="notexactlyFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="devicebl" lay-size="sm" lay-filter="deviceblFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab"style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">借还设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="deviceblDetail" lay-filter="borrowDlFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<%--借还申请新增/批量删除/查询字段--%>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="psub" style="width: 70px">提交</button>
        <button class="layui-btn layui-btn-sm" lay-event="add" style="width: 70px" id="add">新建</button>
        <button class="layui-btn layui-btn-sm" lay-event="pdel" style="width: 100px">批量删除</button>
    </div>
    <div class="demoTable" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"lay-search="" placeholder="请选择" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="RETURN_STATUS">处理状态</option>
                <option value="BORROWER_USER">借用人</option>
                <option value="BORROWER_DETP_ID">借用部门</option>
                <option value="BORROW_TIME">借用日期</option>
                <option value="EXPECT_RETURN_DATE">预计归还日期</option>
                <option value="WORKFLOW_NO">流水号</option>

            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtext"  autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"   lay-event="searchCust" style="height:30px;line-height: 30px; ">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（待批）--%>
<script type="text/html" id="toolbar1">
    <div class="demoTabless" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="RETURN_STATUS">处理状态</option>
                <option value="BORROWER_USER">借用人</option>
                <option value="BORROWER_DETP_ID">借用部门</option>
                <option value="BORROW_TIME">借用日期</option>
                <option value="EXPECT_RETURN_DATE">预计归还日期</option>
                <option value="BORROWER_OPERATION_USER">借出人</option>
                <option value="LEND_DEPT_ID">借出部门</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtextss" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCustss" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（已准）--%>
<script type="text/html" id="toolbar2">
    <div class="demoTablea" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="RETURN_STATUS">处理状态</option>
                <option value="BORROWER_USER">借用人</option>
                <option value="BORROWER_DETP_ID">借用部门</option>
                <option value="BORROW_TIME">借用日期</option>
                <option value="EXPECT_RETURN_DATE">预计归还日期</option>
                <option value="BORROWER_OPERATION_USER">借出人</option>
                <option value="LEND_DEPT_ID">借出部门</option>
                <option value="BORROW_OPERATION_TIME">借出日期</option>
                <option value="APPROVER">审批人</option>
                <option value="APPROVER_TIME">审批日期</option>
                <option value="WORKFLOW_NO">流水号</option>
                <option value="MEMO">备注</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtexta" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCusta" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（未批）--%>
<script type="text/html" id="toolbar3">
    <div class="demoTableb" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="BORROWER_USER">借用人</option>
                <option value="BORROWER_DETP_ID">借用部门</option>
                <option value="BORROW_TIME">借用日期</option>
                <option value="EXPECT_RETURN_DATE">预计归还日期</option>
                <option value="BORROWER_OPERATION_USER">借出人</option>
                <option value="LEND_DEPT_ID">借出部门</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtextb" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCustb" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--设备归还/查询字段--%>
<script type="text/html" id="toolbar4">
    <div class="demoTablec" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="BORROWER_USER">借用人</option>
                <option value="BORROWER_DETP_ID">借用部门</option>
                <option value="BORROW_TIME">借用日期</option>
                <option value="EXPECT_RETURN_DATE">预计归还日期</option>
                <option value="BORROWER_OPERATION_USER">借出人</option>
                <option value="LEND_DEPT_ID">借出部门</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" autocomplete="off"  name="searchtextc" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload" lay-event="searchCustc" style="height:30px;line-height: 30px; ">搜索</button>
        </div>
    </div>
</script>
<%--借还设备明细下头部--%>
<script type="text/html" id="toolbars">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addcont" style="width: 70px">新建</button>
        <button class="layui-btn layui-btn-sm"  style="width: 70px" lay-event="dell">删除</button>
    </div>
</script>
<script type="text/html" id="toolbar1">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="" style="width: 70px">归还</button>
        <button class="layui-btn layui-btn-sm"  style="width: 70px" lay-event="">删除</button>
    </div>
</script>
<%--设备归还操作--%>
<script type="text/html" id="barOperation3">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="returnlend">归还</a>
</script>
<%--借还申请上头部--%>
<script type="text/html" id="barOperation">
    <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="sub" id="sub">提交</a>
    <a class="layui-btn  layui-btn-xs" lay-event="edit" id="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="barOperation3">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/javascript">

    var opencl="";
    var parm = {};
    var url = "";
    var toolb="";
    var searchColum=""
    var newAppli,
        accurateTable,
        approvalTable,
        notexactlyTable,
        devicebl,
        deviceDetail,
        deptId;
    var datat;
    var col =[[{checkbox: true, field: 'lendId'}
        , {field: 'equipNo', title: '固定资产编号'}
        , {field: 'equipName', title: '设备名称'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatuasCode', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
        , {width: 250, title: '操作', align: 'center', toolbar: '#barOperation3'}
    ]]
    var mcol =[[{checkbox: true, field: 'lendId'}
        ,{field: 'equipNo', title: '固定资产编号'}
        , {field: 'equipName', title: '设备名称'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatuasCode', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
    ]]
    var scol = [[{checkbox: true}
        , {field: 'equipNo', title: '固定资产编号'}
        , {field: 'equipName', title: '设备名称'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatuasCode', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
        , {field: 'returnUser', title: '归还人'}
        , {field: 'returnTime', title: '归还时间'}
        , {field: 'returnStatus', title: '归还状态',templet:function(d){
                if (d.returnStatus == 0) {
                    return "未归还"
                } else if (d.returnStatus == 1) {
                    return "已归还"
                }
            }}
         , {width: 100, title: '操作', align: 'center', toolbar: '#barOperation3'}
    ]]
    layui.use(['table', 'layer','laydate', 'form', 'element'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var laydate = layui.laydate;
        var topindexPage = 0;
        newAppli = table.render({
            elem: '#Settlement'
            , data: []
            , page: true //开启分页
            , url: '/EquipBorrow/getequipborrowing'//数据接口
            , toolbar: '#toolbar'
            , where: {"ApprovalStatus": 0}
            , cols: [[ //标题栏
                {type: 'checkbox', field: 'lendId'}
                , {
                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                        if (d.approverStatus == 0) {
                            return "新建"
                        } else if (d.approverStatus == 1) {
                            return "待批准"
                        } else if (d.approverStatus == 2) {
                            return "已批准"
                        } else if (d.approverStatus == 3) {
                            return "未批准"
                        }
                    }
                }
                , {field: 'borrowerUser', title: '借用人',}
                , {field: 'borrowerdeptName', title: '借用部门'}
                , {
                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                        if (d.borrowTime == undefined || d.borrowTime == "") {
                            return d.borrowTime = ""
                        } else {
                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                            return d.borrowTime;
                        }
                    }
                }
                , {
                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                            return d.expectReturnDate = ""
                        } else {
                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                            return d.expectReturnDate;
                        }
                    }
                }
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'memo', title: '备注'}
                , {fixed: 'right',width: "20%", title: '操作', align: 'center', toolbar: '#barOperation'}
            ]]
            ,done:function(res){
                if(res.data.length >0){
                    var lendId = res.data[0].lendId;
                    equipTable("#deviceDetail",lendId,"#toolbars",col)
                }else{
                    cequipTable("#deviceDetail","#toolbars",col)
                }
            }
        })
        //待批申请表头
        accurateTable = table.render({
            elem: '#accurateTable'
            , url: ''
            , data: []
            , page: true //开启分页
            , toolbar: '#toolbar1'
            , where: {"ApprovalStatus": 1}
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[{type: 'checkbox', field: 'lendId'}
                , {
                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                        if (d.approverStatus == 0) {
                            return "新建"
                        } else if (d.approverStatus == 1) {
                            return "待批准"
                        } else if (d.approverStatus == 2) {
                            return "已批准"
                        } else if (d.approverStatus == 3) {
                            return "未批准"
                        }
                    }
                }
                , {field: 'borrowerUser', title: '借用人',}
                , {field: 'borrowerdeptName', title: '借用部门',}
                , {
                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                        if (d.borrowTime == undefined || d.borrowTime == "") {
                            return d.borrowTime = ""
                        } else {
                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                            return d.borrowTime;
                        }
                    }
                }
                , {
                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                            return d.expectReturnDate = ""
                        } else {
                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                            return d.expectReturnDate;
                        }
                    }
                }
                , {field: 'borrowerOperationUser', title: '借出人'}
                , {field: 'lenddeptName', title: '借出部门'}
                , {
                    field: 'borrowOperationTime', title: '借出日期', templet: function (d) {
                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                            return d.borrowOperationTime = ""
                        } else {
                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                            return d.borrowOperationTime;
                        }
                    }
                }
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var lendId = res.data[0].lendId;
                    equipTable("#accurateDetail",lendId,"#",mcol)
                }else{
                    cequipTable("#accurateDetail","#",mcol)
                }
            }

        });
        //已批申请表头
        approvalTable = table.render({
            elem: '#approvalTable'
            , url: ''
            , data: []
            , page: true //开启分页
            , toolbar: '#toolbar2'
            , where: {"ApprovalStatus": 2}
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[{type: 'checkbox', field: 'lendId'}
                , {
                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                        if (d.approverStatus == 0) {
                            return "新建"
                        } else if (d.approverStatus == 1) {
                            return "待批准"
                        } else if (d.approverStatus == 2) {
                            return "已批准"
                        } else if (d.approverStatus == 3) {
                            return "未批准"
                        }
                    }
                }
                , {field: 'borrowerUser', title: '借用人',}
                , {field: 'borrowerdeptName', title: '借用部门'}
                , {
                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                        if (d.borrowTime == undefined || d.borrowTime == "") {
                            return d.borrowTime = ""
                        } else {
                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                            return d.borrowTime;
                        }
                    }
                }
                , {
                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                            return d.expectReturnDate = ""
                        } else {
                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                            return d.expectReturnDate;
                        }
                    }
                }
                , {field: 'borrowerOperationUser', title: '借出人'}
                , {field: 'lenddeptName', title: '借出部门'}
                , {
                    field: 'borrowOperationTime', title: '借出时间', templet: function (d) {
                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                            return d.borrowOperationTime = ""
                        } else {
                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                            return d.borrowOperationTime;
                        }
                    }
                }
                , {field: 'approver', title: '审批人'}

                , {
                    field: 'approverTime', title: '审批时间', templet: function (d) {
                        if (d.approverTime == undefined || d.approverTime == "") {
                            return d.approverTime = ""
                        } else {
                            d.approverTime = new Date(d.approverTime).Format("yyyy-MM-dd");
                            return d.approverTime;
                        }
                    }
                }
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var lendId = res.data[0].lendId;
                    equipTable("#approvalDetail",lendId,"#",mcol)
                }else{
                    cequipTable("#approvalDetail","#",mcol)
                }
            }
        });
        //未准表头
        notexactlyTable = table.render({
            elem: '#notexactlyTable'
            , url: ''
            , data: []
            , where: {"ApprovalStatus": 3}
            , toolbar: '#toolbar3'
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[{type: 'checkbox', field: 'lendId'}
                , {
                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                        if (d.approverStatus == 0) {
                            return "新建"
                        } else if (d.approverStatus == 1) {
                            return "待批准"
                        } else if (d.approverStatus == 2) {
                            return "已批准"
                        } else if (d.approverStatus == 3) {
                            return "未批准"
                        }
                    }
                }
                , {field: 'borrowerUser', title: '借用人',}
                , {field: 'borrowerdeptName', title: '借用部门',}
                , {
                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                        if (d.borrowTime == undefined || d.borrowTime == "") {
                            return d.borrowTime = ""
                        } else {
                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                            return d.borrowTime;
                        }
                    }
                }
                , {
                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                            return d.expectReturnDate = ""
                        } else {
                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                            return d.expectReturnDate;
                        }
                    }
                }
                , {field: 'borrowerOperationUser', title: '借出人'}
                , {field: 'lenddeptName', title: '借出部门'}
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var lendId = res.data[0].lendId;
                    equipTable("#notexactlyDetail",lendId,"#",mcol)
                }else{
                    cequipTable("#notexactlyDetail","#",mcol)
                }
            }
        });
        //设备归还
        devicebl = table.render({
            elem: '#devicebl'
            , url: ''
            , data: []
            , where: {"ApprovalStatus": 2}
            , toolbar: '#toolbar4'
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[{type: 'checkbox', field: 'lendId'}
                , {
                    field: 'returnStatus', title: '处理状态', templet: function (d) {
                        if (d.returnStatus == 0) {
                            return "全部归还"
                        } else if (d.returnStatus == 1) {
                            return "部分归还"
                        } else if (d.returnStatus == 2) {
                            return "未归还"
                        }
                    }
                }
                , {field: 'borrowerUser', title: '借用人',}
                , {field: 'borrowerdeptName', title: '借用部门',}
                , {
                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                        if (d.borrowTime == undefined || d.borrowTime == "") {
                            return d.borrowTime = ""
                        } else {
                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                            return d.borrowTime;
                        }
                    }
                }
                , {
                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                            return d.expectReturnDate = ""
                        } else {
                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                            return d.expectReturnDate;
                        }
                    }
                }
                , {field: 'borrowerOperationUser', title: '借出人'}
                , {field: 'lenddeptName', title: '借出部门'}
                , {
                    field: 'borrowOperationTime', title: '借出时间', templet: function (d) {
                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                            return d.borrowOperationTime = ""
                        } else {
                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                            return d.borrowOperationTime;
                        }
                    }
                }
                , {field: 'approver', title: '审批人',}
                , {
                    field: 'approverTime', title: '审批时间', templet: function (d) {
                        if (d.approverTime == undefined || d.approverTime == "") {
                            return d.approverTime = ""
                        } else {
                            d.approverTime = new Date(d.approverTime).Format("yyyy-MM-dd");
                            return d.approverTime;
                        }
                    }
                }
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'memo', title: '备注'}
                 , {width: 100, title: '操作', align: 'center', toolbar: '#barOperation3'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var lendId = res.data[0].lendId;
                    equipTable("#deviceblDetail",lendId,"#",scol)
                }else{
                    cequipTable("#deviceblDetail","#",scol)
                }
            }
        });
        var indexPage = 0; //获取底部页签下标
        var cont = "";
        var rowindex = "";//行下标
        //顶部页签切换事件
        element.on('tab(tabtoggle)', function (data) {
            topindexPage=data.index;
            var index = data.index;
            switch (index) {
                // case 0:
                //     // equipTable("#deviceDetail","","#",col);
                //     deviceDetail.reload({
                //         url:""
                //     })
                //     break;
                case 1:
                    accurateTable.reload({
                        url:"/EquipBorrow/getequipborrowing"
                    })
                    break;
                case 2:
                    approvalTable.reload({
                        url:"/EquipBorrow/getequipborrowing"
                    })
                    break;
                case 3:
                    notexactlyTable.reload({
                        url:"/EquipBorrow/getequipborrowing"
                    })
                    break;
                case 4:
                    devicebl.reload({
                        url:"/EquipBorrow/getequipborrowing"
                    })
                    break;
            }
        });

        //监听借还申请行事件触发函数
        table.on('row(SettlementFilter)', function (obj) {
            datat = obj.data;
            deptId = datat.lendDeptId;
            var index = $(this).attr('data-index'); //行点击样式
            rowindex = index;
            var tr = $(this).parent().children("tr");
            $(this).toggleClass("tablecolor");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("tablecolor");
                }
            }
            equipTable("#deviceDetail",datat.lendId,"#toolbars",col)
        })
        //监听待批申请行事件触发函数
        table.on('row(accurateTableFilter)', function (obj) {
            datat = obj.data;
            var index = $(this).attr('data-index'); //行点击样式
            rowindex = index;
            var tr = $(this).parent().children("tr");
            $(this).toggleClass("tablecolor");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("tablecolor");
                }
            }

            equipTable("#accurateDetail",datat.lendId,"#",mcol)
        })
        //监听已批申请行事件触发函数
        table.on('row(approvalTableFilter)', function (obj) {
            datat = obj.data;
            var index = $(this).attr('data-index'); //行点击样式
            rowindex = index;
            var tr = $(this).parent().children("tr");
            $(this).toggleClass("tablecolor");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("tablecolor");
                }
            }
            equipTable("#approvalDetail",datat.lendId,"#",mcol)
        })
        //监听未准申请行事件触发函数
        table.on('row(notexactlyTableFilter)', function (obj) {
            datat = obj.data;
            var index = $(this).attr('data-index'); //行点击样式
            rowindex = index;
            var tr = $(this).parent().children("tr");
            $(this).toggleClass("tablecolor");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("tablecolor");
                }
            }
            equipTable("#notexactlyDetail",datat.lendId,"#",mcol)
        })
        //设备归还
        table.on('row(deviceblFilter)', function (obj) {
            datat = obj.data;
            var index = $(this).attr('data-index'); //行点击样式
            rowindex = index;
            var tr = $(this).parent().children("tr");
            $(this).toggleClass("tablecolor");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("tablecolor");
                }
            }
            equipTable("#deviceblDetail",datat.lendId,"#",scol)
        })

        table.on('toolbar(SettlementFilter)', function (obj) {
            // var checkStatus = table.checkStatus(obj.config.id);
            var events = obj.event;
            /*多选删除,增加，多选提交*/
            if (events == 'pdel') {//批量删除
                form.render();
                var data = table.checkStatus('Settlement').data;
                if (data.length > 0) {
                    var lendIds = '';
                    for (var i = 0; i < data.length; i++) {
                        lendIds += data[i].lendId + ","
                    }
                    var parme = {
                        lendId: lendIds,
                    }
                    publicDelete('/EquipBorrow/delLend', parme, newAppli);
                } else {
                    layer.msg("请选中要删除的数据");
                }
            }
            else if (events == 'add') {// 新增客户信息，资质文件，外部联系人信息，银行账户
                var index = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['100%', '100%'], //宽高
                    title: '新增',
                    maxmin: true,
                    content: '/EquipBorrow/addBorrowHtml?begin=add',
                    btn: ["确认", "取消"],
                    end: function () {
                    },
                    yes:function (index,layero) {
                        var jsondata = $(layero).find("iframe")[0].contentWindow.addjData();
                        for(var i=0;i<jsondata.length;i++){
                            jsondata[i].equipStatuasCode = jsondata[i].equipTypeCode;
                        }
                        var limsEquipLend = JSON.stringify(jsondata);
                        var ownerLog = $(layero).find("iframe")[0].contentWindow.addData();
                        ownerLog["lendListJson"]=limsEquipLend;
                        if (jsondata.length == 0 || ownerLog.borrowerDetpId == "" || ownerLog.lendDeptId == "" || ownerLog.borrowerUser == "" || ownerLog.borrowTime == "" || ownerLog.expectReturnDate == ""  || ownerLog.reminderTime == ""||ownerLog.borrowerOperationUser == "") {
                            layer.msg("请填写完整的信息及添加设备！");
                            return false;
                        } else {
                            layer.close(index);
                            $.ajax({
                                type: "post",
                                url: "/EquipBorrow/addequipborrowing",
                                dataType: "json",
                                data: ownerLog,
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        newAppli.reload();
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            })

                        }
                    }
                });
            } else if (events == 'psub') {  //批量提交
                var data = table.checkStatus('Settlement').data;
                if (data.length == 0 || data.length < 0) {
                    layer.msg("请选择一条或者多条进行提交。");
                    return false;
                } else if (data.length > 0) {
                    var lendId = "";
                    var ApprovalStatus ="";
                    for (var i = 0; i < data.length; i++) {
                        lendId += data[i].lendId + ",";
                        ApprovalStatus+="1,";
                    }
                    $.ajax({
                        type: "post",
                        url: "/EquipBorrow/lendApprovalStatus",
                        dataType: "json",
                        data: {
                            lendId: lendId,
                            ApprovalStatus: ApprovalStatus
                        },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                newAppli.reload();
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                }
            }else if(events=='searchCust'){
                var inptext=$(".demoTable input[name='searchtext']").val();
                var seletext=$(".demoTable").find("dl dd.layui-this").attr("lay-value");
                if((inptext == "")&&(seletext==undefined)){
                    layer.msg("请输入需要搜索的条件");
                    return false;
                }else if((inptext=="")&&(seletext!=undefined)){
                    layer.msg("请输入需要查询的条件");
                    return false;
                }else if((inptext!="")&&(seletext==undefined)){
                    layer.msg("请选择查询的字段");
                    return false;
                }else{
                    var datas={
                        inptext:inptext,
                        column:seletext
                    }
                    searchCusInfo(datas)
                }

            }
            // 子调父关闭弹框方法
            function close() {
                layer.closeAll();
            }
        });
        // 新用户申请/编辑/删除操作
        table.on('tool(SettlementFilter)', function (obj) {
            //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据

            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            var ids = data.lendId+",";
            if (layEvent === 'sub') {
                var ids = data.lendId;
                $.ajax({
                    type: "post",
                    url: "/EquipBorrow/lendApprovalStatus",
                    dataType: "json",
                    data: {
                        lendId: ids,
                        ApprovalStatus: 1
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg);
                            newAppli.reload();
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                })
                // publicSub('/EquipBorrow/lendApprovalStatus', parme, newAppli, table);
                //向服务端发送提交指令

            } else if (layEvent === 'del') {
                var parme = {
                    lendId: data.lendId,
                }
                publicDelete('/EquipBorrow/delLend', parme, newAppli);
                //向服务端发送删除指令
            } else if (layEvent === 'edit') { //编辑
                layer.open({
                    type: 2,
                    skin: false, //加上边框
                    area: ['90%', '90%'], //宽高
                    title: '编辑申请',
                    maxmin: true,
                    btn: ["确定", "取消"],
                    btnAlign: 'c',
                    content: '/EquipBorrow/addBorrowHtml?begin=edit&lendId='+data.lendId
                    , success: function (res) {
                    },
                    yes: function (index, layero) {
                        var limsEquipLend = $(layero).find("iframe")[0].contentWindow.addData();
                        limsEquipLend.lendId = data.lendId;
                        if (limsEquipLend.borrowerDetpId == "" || limsEquipLend.lendDeptId == "" || limsEquipLend.borrowerUser == "" || limsEquipLend.borrowTime == "" || limsEquipLend.expectReturnDate == "" || limsEquipLend.reminderTime == "" || limsEquipLend.borrowerOperationUser == "") {
                            layer.msg("请填写完整的信息及添加设备！");
                            return false;
                        } else {
                            layer.close(index);
                            $.ajax({
                                type: "post",
                                url: "/EquipBorrow/updeLendById",
                                dataType: "json",
                                data: limsEquipLend,
                                success: function (res) {
                                    layer.msg(res.msg, {
                                        icon: 6,//提示的样式
                                        time: 600, //1秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒)
                                        end: function () {
                                            newAppli.reload();
                                        }
                                    })
                                }
                            })
                        }
                    }
                })
            }
        });
        //明细表头监听事件
        table.on('toolbar(deviceFilter)', function (obj) {
            var events = obj.event;
            var data = [];
            data = layui.table.checkStatus('Settlement').data;
            if (events == 'addcont') {
                if (deptId == undefined || deptId=="undefined") {
                    layer.msg("请选择需要修改设备信息的申请");
                    return false;
                }else {
                }
                var index = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['90%', '90%'], //宽高
                    title: '选择设备',
                    maxmin: true,
                    btn: ['提交', '取消'],
                    content: '/EquipBorrow/indexList?deptId='+datat.lendDeptId,
                    success: function () {
                        var paymentYn = 0;
                        form.render();//初始化表单

                    },
                    yes: function (index, layero) {
                        var jsondata = $(layero).find("iframe")[0].contentWindow.addjData();
                        for(var i=0;i<jsondata.length;i++){
                            jsondata[i].lendId = datat.lendId;
                            jsondata[i].equipStatuasCode = jsondata[i].equipTypeCode;
                        }
                        var lendListJson = JSON.stringify(jsondata);
                        layer.close(index);
                        $.ajax({
                            type: "post",
                            url: "/EquipBorrow/addlendList",
                            dataType: "json",
                            data: {
                                lendListJson:lendListJson
                            },
                            success: function (res) {
                                if (res.code == 0) {
                                    layer.msg(res.msg);
                                    equipTable("#deviceDetail",datat.lendId,"#toolbars",col);
                                    // newAppli.reload();
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        })
                    }
                });
            } else if (events == 'dell') {
                var deldata = layui.table.checkStatus('deviceDetail').data;
                var ids = ""
                for (var i = 0; i < deldata.length; i++) {
                    ids += deldata[i].lendListId + ",";
                }
                if (deldata.length == 0 || deldata.length < 0) {
                    layer.msg("请选择一条或者多条进行删除。");
                    return false;
                } else if (deldata.length > 0) {
                    $.ajax({
                        type: "post",
                        url: "/EquipBorrow/delLendList",
                        dataType: "json",
                        data: {
                            lendListId:ids
                        },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                table.reload('deviceDetail')
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                }
            }
        })
        //明细操作栏事件
        table.on('tool(deviceFilter)', function (obj) {
            var events = obj.event;
            var datatr = obj.data;
            if (events == 'delete') {
                var param = {
                    lendListId: datatr.lendListId
                }
                layer.confirm('确定要删除吗?', {icon: 5, title: '提示'}, function (index) {
                    $.post("/EquipBorrow/delLendList", param, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg);
                            table.reload('deviceDetail')
                        }
                    });
                })
            }
        })


        /** 创建作者:   王穗穗
         * 创建日期:   12:15 2019/10/19
         * 方法介绍:
         * 参数说明:  设备借还单归还
         * @return
         */
        table.on('tool(deviceblFilter)', function (obj) {
            var events = obj.event;
            var data=obj.data;
            if (events == 'returnlend') {
                if(data.returnStatus==0){
                    layer.msg("设备已全部归还");
                    return false;
                }
                resutltopen("/EquipBorrow/Returnborrowing",data,"devicebl")
            }
        });

        /** 创建作者:   王穗穗
         * 创建日期:   10:35 2019/10/19
         * 方法介绍:
         * 参数说明:  设备归还
         * @return
         */
        table.on('tool(borrowDlFilter)', function (obj) {
            var events = obj.event;
            var data=obj.data;
            if (events == 'returnlend') {
                if(data.returnStatus==1){
                    layer.msg("设备已归还");
                    return false;
                }
                resutltopen("/EquipBorrow/Returnquipborrowing",data,"devicebl")
            }

        });

        /***********************************自定义方法区**********************************/
        //模糊查询
        function searchCusInfo(data) {
            var parm={}
            var toolb;
            var clo;
            var tableName;
            // var url="/equipTransfer/adminastorList"
            if(data.column=="RETURN_STATUS"){
                if(data.inptext=="部分归还"){
                    data.inptext=1;
                }if(data.inptext=="全部归还"){
                    data.inptext=2
                }if(data.inptext=="未归还"){
                    data.inptext=0;
                }
            }
            var url="/EquipBorrow/getequipborrowing"
            if (topindexPage == 0) {
                parm = {
                    ApprovalStatus: 0,
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;
                        layui.table.render({
                            elem: '#Settlement'
                            , data: datas
                            , page: true //开启分页
                            , url: ''//数据接口
                            , toolbar: '#toolbar'
                            , cols: [[ //标题栏
                                {type: 'checkbox', field: 'lendId'}
                                , {
                                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                                        if (d.approverStatus == 0) {
                                            return "新建"
                                        } else if (d.approverStatus == 1) {
                                            return "待批准"
                                        } else if (d.approverStatus == 2) {
                                            return "已批准"
                                        } else if (d.approverStatus == 3) {
                                            return "未批准"
                                        }
                                    }
                                }
                                , {field: 'borrowerUser', title: '借用人',}
                                , {field: 'borrowerdeptName', title: '借用部门'}
                                , {
                                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                                        if (d.borrowTime == undefined || d.borrowTime == "") {
                                            return d.borrowTime = ""
                                        } else {
                                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                                            return d.borrowTime;
                                        }
                                    }
                                }
                                , {
                                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                                            return d.expectReturnDate = ""
                                        } else {
                                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                                            return d.expectReturnDate;
                                        }
                                    }
                                }
                                , {field: 'workflowNo', title: '流水号'}
                                , {field: 'memo', title: '备注'}
                                , {width: 250, title: '操作', align: 'center', toolbar: '#barOperation'}
                            ]]
                            ,done:function(res){
                                if(res.data.length >0){
                                    var lendId = res.data[0].lendId;
                                    equipTable("#deviceDetail",lendId,"#toolbars",col)
                                }else{
                                    cequipTable("#deviceDetail","#toolbars",col)
                                }
                                $(".demoTable input[name='searchtext']").val(data.inptext);
                                $(".demoTable").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        })
                    }

                })
            } else if (topindexPage == 1) {
                parm = {
                    ApprovalStatus: 1,
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;
                        layui.table.render({
                            elem: '#accurateTable'
                            , url: ''
                            , data: []
                            , page: true //开启分页
                            , toolbar: '#toolbar1'
                            , where: {"ApprovalStatus": 1}
                            , limit: 5 //每页默认显示的数量, limits: [5, 10, 15, 20, 25, 30]
                            , cols: [[{type: 'checkbox', field: 'lendId'}

                                , {
                                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                                        if (d.approverStatus == 0) {
                                            return "新建"
                                        } else if (d.approverStatus == 1) {
                                            return "待批准"
                                        } else if (d.approverStatus == 2) {
                                            return "已批准"
                                        } else if (d.approverStatus == 3) {
                                            return "未批准"
                                        }
                                    }
                                }
                                , {field: 'borrowerUser', title: '借用人',}
                                , {field: 'borrowerdeptName', title: '借用部门',}
                                , {
                                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                                        if (d.borrowTime == undefined || d.borrowTime == "") {
                                            return d.borrowTime = ""
                                        } else {
                                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                                            return d.borrowTime;
                                        }
                                    }
                                }
                                , {
                                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                                            return d.expectReturnDate = ""
                                        } else {
                                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                                            return d.expectReturnDate;
                                        }
                                    }
                                }
                                , {field: 'borrowerOperationUser', title: '借出人'}
                                , {field: 'lenddeptName', title: '借出部门'}
                                , {
                                    field: 'borrowOperationTime', title: '借出日期', templet: function (d) {
                                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                                            return d.borrowOperationTime = ""
                                        } else {
                                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                                            return d.borrowOperationTime;
                                        }
                                    }
                                }
                                , {field: 'workflowNo', title: '流水号'}
                                , {field: 'memo', title: '备注'}
                            ]]
                            ,done:function (res) {
                                if(res.data.length >0){
                                    var lendId = res.data[0].lendId;
                                    equipTable("#accurateDetail",lendId,"#",mcol)
                                }else{
                                    cequipTable("#accurateDetail","#",mcol)
                                }
                                // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                                // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                                $(".demoTabless input[name='searchtextss']").val(data.inptext);
                                $(".demoTabless").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        });
                    }
                })
            } else if (topindexPage == 2) {
                parm = {
                    ApprovalStatus: 2,
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;

                        layui.table.render({
                            elem: '#approvalTable'
                            , url: ''
                            , data: datas
                            , page: true //开启分页
                            , toolbar: '#toolbar2'
                            , limit: 5 //每页默认显示的数量
                            , limits: [5, 10, 15, 20, 25, 30]
                            , cols: [[{type: 'checkbox', field: 'lendId'}
                                , {
                                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                                        if (d.approverStatus == 0) {
                                            return "新建"
                                        } else if (d.approverStatus == 1) {
                                            return "待批准"
                                        } else if (d.approverStatus == 2) {
                                            return "已批准"
                                        } else if (d.approverStatus == 3) {
                                            return "未批准"
                                        }
                                    }
                                }
                                , {field: 'borrowerUser', title: '借用人',}
                                , {field: 'borrowerdeptName', title: '借用部门'}
                                , {
                                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                                        if (d.borrowTime == undefined || d.borrowTime == "") {
                                            return d.borrowTime = ""
                                        } else {
                                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                                            return d.borrowTime;
                                        }
                                    }
                                }
                                , {
                                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                                            return d.expectReturnDate = ""
                                        } else {
                                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                                            return d.expectReturnDate;
                                        }
                                    }
                                }
                                , {field: 'borrowerOperationUser', title: '借出人'}
                                , {field: 'lenddeptName', title: '借出部门'}
                                , {
                                    field: 'borrowOperationTime', title: '借出时间', templet: function (d) {
                                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                                            return d.borrowOperationTime = ""
                                        } else {
                                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                                            return d.borrowOperationTime;
                                        }
                                    }
                                }
                                , {field: 'approver', title: '审批人'}

                                , {
                                    field: 'approverTime', title: '审批时间', templet: function (d) {
                                        if (d.approverTime == undefined || d.approverTime == "") {
                                            return d.approverTime = ""
                                        } else {
                                            d.approverTime = new Date(d.approverTime).Format("yyyy-MM-dd");
                                            return d.approverTime;
                                        }
                                    }
                                }
                                , {field: 'workflowNo', title: '流水号'}
                                , {field: 'memo', title: '备注'}
                            ]]
                            ,done:function (res) {
                                if(res.data.length >0){
                                    var lendId = res.data[0].lendId;
                                    equipTable("#approvalDetail",lendId,"#",mcol)
                                }else{
                                    cequipTable("#approvalDetail","#",mcol)
                                }
                                $(".demoTablea input[name='searchtexta']").val(data.inptext);
                                $(".demoTablea").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        });
                    }
                })
            } else if (topindexPage == 3) {
                parm = {
                    ApprovalStatus: 3,
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;
                        layui.table.render({
                            elem: '#notexactlyTable'
                            , url: ''
                            , data: datas
                            , toolbar: '#toolbar3'
                            , page: true //开启分页
                            , limit: 5 //每页默认显示的数量
                            , limits: [5, 10, 15, 20, 25, 30]
                            , cols: [[{type: 'checkbox', field: 'lendId'}
                                , {
                                    field: 'approverStatus', title: '审批状态', templet: function (d) {
                                        if (d.approverStatus == 0) {
                                            return "新建"
                                        } else if (d.approverStatus == 1) {
                                            return "待批准"
                                        } else if (d.approverStatus == 2) {
                                            return "已批准"
                                        } else if (d.approverStatus == 3) {
                                            return "未批准"
                                        }
                                    }
                                }
                                , {field: 'borrowerUser', title: '借用人',}
                                , {field: 'borrowerdeptName', title: '借用部门',}
                                , {
                                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                                        if (d.borrowTime == undefined || d.borrowTime == "") {
                                            return d.borrowTime = ""
                                        } else {
                                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                                            return d.borrowTime;
                                        }
                                    }
                                }
                                , {
                                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                                            return d.expectReturnDate = ""
                                        } else {
                                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                                            return d.expectReturnDate;
                                        }
                                    }
                                }
                                , {field: 'borrowerOperationUser', title: '借出人'}
                                , {field: 'lenddeptName', title: '借出部门'}
                                , {field: 'workflowNo', title: '流水号'}
                                , {field: 'memo', title: '备注'}
                            ]]
                            ,done:function (res) {
                                if(res.data.length >0){
                                    var lendId = res.data[0].lendId;
                                    equipTable("#notexactlyDetail",lendId,"#",mcol)
                                }else{
                                    cequipTable("#notexactlyDetail","#",mcol)
                                }
                                // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                                // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                                $(".demoTableb input[name='searchtextb']").val(data.inptext);
                                $(".demoTableb").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        });
                    }
                })
            } else if (topindexPage == 4) {
                if(data.column=="RECEIVE_STATUS"){
                    if(data.inptext=="全部接收"){
                        data.inptext=2
                    }
                    if(data.inptext=="部分接收"){
                        data.inptext=1
                    }
                    if(data.inptext=="未接收"){
                        data.inptext=0
                    }

                }
                parm = {
                    ApprovalStatus:2,
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;
                        layui.table.render({
                            elem: '#devicebl'
                            , url: ''
                            , data: datas
                            , toolbar: '#toolbar4'
                            , page: true //开启分页
                            , limit: 5 //每页默认显示的数量
                            , limits: [5, 10, 15, 20, 25, 30]
                            , cols: [[{type: 'checkbox', field: 'lendId'}
                                , {
                                    field: 'returnStatus', title: '处理状态', templet: function (d) {
                                        if (d.returnStatus == 0) {
                                            return "全部归还"
                                        } else if (d.returnStatus == 1) {
                                            return "部分归还"
                                        } else if (d.returnStatus == 2) {
                                            return "未归还"
                                        }
                                    }
                                }
                                , {field: 'borrowerUser', title: '借用人',}
                                , {field: 'borrowerdeptName', title: '借用部门',}
                                , {
                                    field: 'borrowTime', title: '借用日期', templet: function (d) {
                                        if (d.borrowTime == undefined || d.borrowTime == "") {
                                            return d.borrowTime = ""
                                        } else {
                                            d.borrowTime = new Date(d.borrowTime).Format("yyyy-MM-dd");
                                            return d.borrowTime;
                                        }
                                    }
                                }
                                , {
                                    field: 'expectReturnDate', title: '预计归还日期', templet: function (d) {
                                        if (d.expectReturnDate == undefined || d.expectReturnDate == "") {
                                            return d.expectReturnDate = ""
                                        } else {
                                            d.expectReturnDate = new Date(d.expectReturnDate).Format("yyyy-MM-dd");
                                            return d.expectReturnDate;
                                        }
                                    }
                                }
                                , {field: 'borrowerOperationUser', title: '借出人'}
                                , {field: 'lenddeptName', title: '借出部门'}
                                , {
                                    field: 'borrowOperationTime', title: '借出时间', templet: function (d) {
                                        if (d.borrowOperationTime == undefined || d.borrowOperationTime == "") {
                                            return d.borrowOperationTime = ""
                                        } else {
                                            d.borrowOperationTime = new Date(d.borrowOperationTime).Format("yyyy-MM-dd");
                                            return d.borrowOperationTime;
                                        }
                                    }
                                }
                                , {field: 'approver', title: '审批人',}
                                , {
                                    field: 'approverTime', title: '审批时间', templet: function (d) {
                                        if (d.approverTime == undefined || d.approverTime == "") {
                                            return d.approverTime = ""
                                        } else {
                                            d.approverTime = new Date(d.approverTime).Format("yyyy-MM-dd");
                                            return d.approverTime;
                                        }
                                    }
                                }
                                , {field: 'workflowNo', title: '流水号'}
                                , {field: 'memo', title: '备注'}
                            ]]
                            ,done:function (res) {
                                if(res.data.length >0){
                                    var lendId = res.data[0].lendId;
                                    equipTable("#deviceblDetail",lendId,"#",scol)
                                }else{
                                    cequipTable("#deviceblDetail","#",scol)
                                }
                                // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                                // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                                $(".demoTablec input[name='searchtextc']").val(data.inptext);
                                $(".demoTablec").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        });
                    }
                })
            }

        }
        //公共删除方法
        function publicDelete(url, data, tableName) {
            layer.confirm('确定要删除吗?', {icon: 5, title: '提示'}, function (index) {
                var res = toAjax(url, data, tableName);
                var ids = "";
                if (res.code == 0) {
                    if (data.lendId != undefined && data.lendId != null && data.lendId != "") {
                        ids = data.lendId
                        var page = $(".layui-laypage-skip .layui-input").val();
                    }
                    try {
                        if (ids.substring(ids.length - 1) == ",") {
                            ids = ids.substring(0, ids.length - 1);
                        }
                        var dataSize = ids.split(",");
                        var dataAll = table.cache[tableName.config.id];
                        if (dataAll.length == dataSize.length) {
                            //得到当前页
                            if (page > 1) {
                                tableName.reload({
                                        page: {
                                            curr: page - 1 //重新从第 1 页开始
                                        }
                                    }
                                );
                            } else {
                                tableName = tableName.reload();
                            }
                        } else {
                            tableName = tableName.reload();
                        }
                    } catch (e) {
                        tableName.reload();
                    }
                }
                layer.close(index);
            });
        }

        function crmCustomerAppr(url, data, table) {
            layer.confirm('确定要提交吗?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: url,
                    data: data,
                    type: 'post',
                    async: false,
                    dataType: 'json',
                    success: function (res) {
                        layer.msg(res.msg);
                        layer.close()
                        table.reload();
                    }
                });
            });

        }
        //待批
        table.on('toolbar(accurateTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCustss':
                    var inptext=$(".demoTabless input[name='searchtextss']").val();
                    var seletext=$(".demoTabless").find("dl dd.layui-this").attr("lay-value");
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        // 已批头部事件
        table.on('toolbar(approvalTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCusta':
                    var inptext=$(".demoTablea input[name='searchtexta']").val();
                    var seletext=$(".demoTablea").find("dl dd.layui-this").attr("lay-value");
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        // 未准表头部事件
        table.on('toolbar(notexactlyTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCustb':
                    var inptext=$(".demoTableb input[name='searchtextb']").val();
                    var seletext=$(".demoTableb").find("dl dd.layui-this").attr("lay-value");
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        // 设备接收头部事件
        table.on('toolbar(deviceblFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCustc':
                    var inptext=$(".demoTablec input[name='searchtextc']").val();
                    var seletext=$(".demoTablec").find("dl dd.layui-this").attr("lay-value");
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
    });
    /---------------------------------------------------------------------------自定义方法区------------------------------------------------------------------------------------------/

    /**  归还具体操作 **/
    function resutltopen(url,data,table){
        var index = layer.open({
            type: 1,
            area: ['500px', '300px'], //宽高
            title: '归还信息',
            maxmin: true,
            btn: ['提交', '取消'],
            content: '<form class="layui-form"  lay-filter="formTest" >' +
                '<div class="one" id="PositionName"><div class="layui-form-item" style="margin: 20px 0;"><label class="layui-form-label" style="width: 150px;"><span style="color: red">*</span>归还人：</label><div class="layui-input-inline" id="tre" style="width: 200px;">' +
                '<div class="layui-input" onclick="xuanren()" style="height: 30px;line-height: 30px;"id="returnUser"></div>'+
                '<input type="text" hidden name="name="returnUser">'+
                '<input type="text" disabled name="borrowerUser"  placeholder="请输入" autocomplete="off" class="layui-input" style="display: none;"></div></div></div>'+
                '<div class="one"><div class="layui-form-item"><label class="layui-form-label" style="width: 150px;">归还时间：</label><div class="layui-input-inline" style="width: 200px;">' +
                '<input placeholder="请输入" disabled id="returnTime" style="color:#888;height: 32px;" type="text" name="returnTime" autocomplete="off" class="layui-input"></div></div></div>' +
                '</form>',
            success: function () {
                $("#returnTime").val(nowformat);
                layui.form.render();
            },
            yes: function (index, layero) {
                if($("#returnUser").next().val()==""){
                    layui.layer.msg("请选择归还人");
                    return false;
                }
                var param={};
                if(data.lendListId==undefined){
                    param={
                        returnUser:$("#returnUser").next().val(),
                        lendId:data.lendId
                    }
                }else {
                    param = {
                        lendListId: data.lendListId,
                        equipId: data.equipId,
                        returnUser: $("#returnUser").next().val(),
                        lendId: data.lendId
                    }
                }
                layui.layer.close(index);
                toAjax(url,param,table,data.lendId);
            }
        });
    }

    function toAjax(url, data, table,lendId) {
        var result;
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            async: false,
            dataType: 'json',
            success: function (res) {
                result = res;
                layer.msg(res.msg);
                devicebl.reload();
                equipTable("#deviceblDetail",lendId,"#",scol)
            }
        });
        return result;
    }

    //选人员
    function xuanren(me) {
        $.popWindow("../common/lmisSelectUserExp?0");
    }
    function close(){
        layer.closeAll();
    }
    function openclose(idkey){
        // var datas = data.field;
        $.ajax({
            type:"post",
            url: '/customer/selectAppBank',
            dataType:'json',
            data:{applicId:idkey},
            success:function(data){
                opencl =data.object.isExit;
                alert(opencl)
            }
        })
    }
    // 明细表格实例渲染
    function equipTable(eid,logid,tid,col) {
        layui.table.render({
            elem: eid
            , url: '/EquipBorrow/getLendList?lendId='+logid
            , data: []
            ,toolbar:tid
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols:col
        });
    }
    function cequipTable(gid,tid,col) {
        layui.table.render({
            elem: gid
            ,data:[]
            ,toolbar:tid
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: col
        });
    }
    //获取当前时间  年月日
    function nowformat() {
        var nstr = "";
        var now = new Date();
        var nyear = now.getFullYear();
        var nmonth = now.getMonth() + 1;
        var nday = now.getDate();
        if (nmonth < 10) {
            nmonth = "0" + nmonth;
        }
        if (nday < 10) {
            nday = "0" + nday;
        }
        nstr = nyear + "-" + nmonth + "-" + nday;
        return nstr;
    }

    /** 创建作者:   王穗穗
     * 创建日期:   11:26 2019/10/19
     * 方法介绍:
     * 参数说明:   设备归还回显数据
     * @return
     */
    function returnlendlist(res){
        $("#returnUser").text(res.userName);
        $("#returnUser").next().val(res.userIds);
    }
</script>
</body>
</html>
